package com.bootdo.wx.controller;

import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import com.bootdo.wx.domain.DataRangeDO;
import com.bootdo.wx.service.DataRangeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 检测参数正常范围表
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2021-03-12 16:22:20
 */
 
@Controller
@RequestMapping("/wx/dataRange")
public class DataRangeController {
	@Autowired
	private DataRangeService dataRangeService;
	
	@GetMapping()
	@RequiresPermissions("wx:dataRange:dataRange")
	String DataRange(){
	    return "wx/dataRange/dataRange";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("wx:dataRange:dataRange")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<DataRangeDO> dataRangeList = dataRangeService.list(query);
		int total = dataRangeService.count(query);
		PageUtils pageUtils = new PageUtils(dataRangeList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("wx:dataRange:add")
	String add(){
	    return "wx/dataRange/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("wx:dataRange:edit")
	String edit(@PathVariable("id") String id,Model model){
		DataRangeDO dataRange = dataRangeService.get(id);
		model.addAttribute("dataRange", dataRange);
	    return "wx/dataRange/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("wx:dataRange:add")
	public R save( DataRangeDO dataRange){
		if(dataRangeService.save(dataRange)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("wx:dataRange:edit")
	public R update( DataRangeDO dataRange){
		dataRangeService.update(dataRange);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("wx:dataRange:remove")
	public R remove( String id){
		if(dataRangeService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("wx:dataRange:batchRemove")
	public R remove(@RequestParam("ids[]") String[] ids){
		dataRangeService.batchRemove(ids);
		return R.ok();
	}
	
}
